package com.redoor.app.stake.basicdata.controller;

import com.github.pagehelper.PageInfo;
import com.redoor.app.stake.basicdata.model.BaseChargerCriteria;
import com.redoor.app.stake.basicdata.model.controllerModel.BaseStationCriteria;
import com.redoor.app.stake.basicdata.service.BaseChargerService;
import com.redoor.app.stake.basicdata.service.BaseStationService;
import com.redoornetwork.framework.core.response.ResponseResult;
import com.redoornetwork.framework.core.response.ResultGenerator;
import com.yotouch.app.stake.hsf.ChargerService;
import com.yotouch.app.stake.hsf.StationService;
import com.yotouch.app.stake.model.Charger;
import com.yotouch.app.stake.model.Station;
import com.yotouch.app.stake.model.response.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by wangjunlei on 2018/2/13.
 */

@RestController
@RequestMapping("/api/chargers")
@Api(value = "提供HSF枪接口API")
public class HSFChargerAPIController {

    @Autowired
    private ChargerService chargerService;

    @ApiOperation(value = "查询枪数据", notes = "查询枪数据")
    @PostMapping("/constomer/hsfChargers")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "limit", value = "偏移量", paramType = "query", dataType = "int", required = true, defaultValue = "20"),
            @ApiImplicitParam(name = "offset", value = "起始记录", paramType = "query", dataType = "int", required = true, defaultValue = "1")
    })
    public ResponseResult hsfChargers(BaseChargerCriteria criteria) {
        ResponseChargerList chargers = chargerService.list(criteria.getLimit(),criteria.getOffset());

        return ResultGenerator.generatorSuccess(chargers);
    }

    @ApiOperation(value = "sgccTotalCount", notes = "sgccTotalCount")
    @PostMapping("/constomer/sgccTotalCount")
    public ResponseResult sgccTotalCount() {
        int count = chargerService.sgccTotalCount().getValue();

        return ResultGenerator.generatorSuccess(count);
    }

    @ApiOperation(value = "totalCount", notes = "totalCount")
    @PostMapping("/constomer/totalCount")
    public ResponseResult totalCount() {
        int count = chargerService.totalCount().getValue();

        return ResultGenerator.generatorSuccess(count);
    }

    @ApiOperation(value = "sgccCharger查询国网枪数据", notes = "sgccCharger查询国网枪数据")
    @PostMapping("/constomer/sgccCharger_guowang")
    public ResponseResult sgccCharger_guowang() {
        ResponseChargerList list = chargerService.sgccCharger(0,10);

        PageInfo pageInfo = new PageInfo(list.getChargerList());
        pageInfo.setTotal(1000);
        return ResultGenerator.generatorSuccess(pageInfo);
    }

    @ApiOperation(value = "listByStakeNo", notes = "listByStakeNo")
    @PostMapping("/constomer/listByStakeNo")
    public ResponseResult listByStakeNo(String stakeNo) {
        ResponseChargerList list = chargerService.listByStakeNo(stakeNo);

        PageInfo pageInfo = new PageInfo(list.getChargerList());
        pageInfo.setTotal(1000);
        return ResultGenerator.generatorSuccess(pageInfo);
    }

    @ApiOperation(value = "listByStation", notes = "listByStation")
    @PostMapping("/constomer/listByStation")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "stationUuid", value = "站主键", paramType = "query", dataType = "String", required = true, defaultValue = ""),
            @ApiImplicitParam(name = "limit", value = "偏移量", paramType = "query", dataType = "int", required = true, defaultValue = "20"),
            @ApiImplicitParam(name = "offset", value = "起始记录", paramType = "query", dataType = "int", required = true, defaultValue = "1")
    })
    public ResponseResult listByStation(String stationUuid,int limit,int offset) {
        ResponseChargerList list = chargerService.listByStation(stationUuid,limit,offset);

        PageInfo pageInfo = new PageInfo(list.getChargerList());
        pageInfo.setTotal(1000);
        return ResultGenerator.generatorSuccess(pageInfo);
    }

    @ApiOperation(value = "countByStation", notes = "countByStation")
    @PostMapping("/constomer/countByStation")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "stationUuid", value = "站主键", paramType = "query", dataType = "String", required = true, defaultValue = "")
    })
    public ResponseResult countByStation(String stationUuid) {
        ResponseInt count = chargerService.countByStation(stationUuid);

        return ResultGenerator.generatorSuccess(count);
    }

    @ApiOperation(value = "countByParking", notes = "countByParking")
    @PostMapping("/constomer/countByParking")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "spaceuuid", value = "停车位主键", paramType = "query", dataType = "String", required = true, defaultValue = "")
    })
    public ResponseResult countByParking(String spaceuuid) {
        ResponseInt count = chargerService.countByParking(spaceuuid);

        return ResultGenerator.generatorSuccess(count);
    }

    @ApiOperation(value = "listByParking", notes = "listByParking")
    @PostMapping("/constomer/listByParking")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "spaceuuid", value = "停车位主键", paramType = "query", dataType = "String", required = true, defaultValue = "")
    })
    public ResponseResult listByParking(String spaceuuid) {
        ResponseChargerList chargers = chargerService.listByParking(spaceuuid,0,20);

        PageInfo pageInfo = new PageInfo(chargers.getChargerList());
        pageInfo.setTotal(1000);
        return ResultGenerator.generatorSuccess(pageInfo);
    }

    @ApiOperation(value = "get", notes = "get")
    @PostMapping("/constomer/get")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "uuid", value = "枪主键", paramType = "query", dataType = "String", required = true, defaultValue = "")
    })
    public ResponseResult get(String uuid) {
        ResponseCharger charger = chargerService.get(uuid);

        return ResultGenerator.generatorSuccess(charger);
    }

    @ApiOperation(value = "getByStakeNoAndChargerNo", notes = "getByStakeNoAndChargerNo")
    @PostMapping("/constomer/getByStakeNoAndChargerNo")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "chargerNo", value = "枪编码", paramType = "query", dataType = "String", required = true, defaultValue = ""),
            @ApiImplicitParam(name = "stakeNo", value = "桩编码", paramType = "query", dataType = "String", required = true, defaultValue = "")
    })
    public ResponseResult get(String chargerNo,String stakeNo) {
        ResponseCharger charger = chargerService.get(stakeNo,chargerNo);

        return ResultGenerator.generatorSuccess(charger);
    }

    @ApiOperation(value = "listByParkingArea", notes = "listByParkingArea")
    @PostMapping("/constomer/listByParkingArea")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "parkingAreaUuid", value = "停车区主键", paramType = "query", dataType = "String", required = true, defaultValue = "")
    })
    public ResponseResult listByParkingArea(String parkingAreaUuid) {
        ResponseChargerList chargers = chargerService.listByParkingArea(parkingAreaUuid);

        return ResultGenerator.generatorSuccess(chargers);
    }

}
